﻿using System;
using System.IO;
using Moq;
using NUnit.Framework;
using OpenWaves.ImageTransformations;
using OpenWaves.Web.Controls;
using OpenWaves.Web.ImageTransformations;

namespace OpenWaves.UnitTests.Web.ImageTransformations
{
/*
    [TestFixture]
    public class WebImageTransformationServiceTests
    {
        [Test]
        public void WhenOpeningFileFailsThenFileShouldBeDeletedFromConcurrentFileStore()
        {
            var virtualPathProviderMock = new Mock<IVirtualFileProvider>(MockBehavior.Strict);
            var concurrentFileStoreMock = new Mock<IConcurrentFileStore>(MockBehavior.Strict);
            var virtualFileMock = new Mock<IVirtualFile>(MockBehavior.Strict);

            Url sourceUrl = Url.Parse("/sourceImage.jpg");
            virtualPathProviderMock.Setup(s => s.GetFile(sourceUrl)).Returns(virtualFileMock.Object);


            Url nullUrl;
            Url fileUrl;
            Stream fileStream;
            concurrentFileStoreMock.Setup(s => s.TryGetFileUrl(It.IsAny<string>(), It.IsAny<TimeSpan>(), out nullUrl)).Returns(false);
            concurrentFileStoreMock.Setup(s => s.TryCreateFile(It.IsAny<string>(), out fileUrl, out fileStream)).Returns(true);
            concurrentFileStoreMock.Setup(s => s.Delete(It.IsAny<string>())).Verifiable();


            virtualFileMock.SetupGet(f => f.Url).Returns(sourceUrl);
            virtualFileMock.SetupGet(f => f.Hash).Returns("123");
            virtualFileMock.Setup(f => f.Open()).Throws(new IOException());


            var transformationService = new WebImageTransformationService(
                virtualPathProviderMock.Object, 
                concurrentFileStoreMock.Object, 
                new Mock<IImageTransformationService>().Object);

            try
            {
                transformationService.GetTransformedImageUrl(sourceUrl, new Mock<IImageTransformation>().Object);

                Assert.Fail("Exception expected");
            }
            catch (ImageTransformationException)
            {
            }

            concurrentFileStoreMock.Verify();
        }
    }
*/

}